package com.ruoyi.web.sso.controller;

import java.util.List;

import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.sso.domain.Alliance;
import com.ruoyi.web.sso.service.IAllianceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 加盟信息Controller
 * 
 * @author ruoyi
 * @date 2022-01-08
 */
@Controller
@RequestMapping("/sso/alliance")
@Api(tags = "加盟 - 内系统")
public class AllianceController extends BaseController
{
    private String prefix = "sso/alliance";

    @Autowired
    private IAllianceService allianceService;

    @RequiresPermissions("sso:alliance:view")
    @GetMapping()
    public String alliance()
    {
        return prefix + "/alliance";
    }

    /**
     * 查询加盟信息列表
     */
    @RequiresPermissions("sso:alliance:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Alliance alliance)
    {
        startPage();
        List<Alliance> list = allianceService.selectAllianceList(alliance);
        return getDataTable(list);
    }

    /**
     * 导出加盟信息列表
     */
    @RequiresPermissions("sso:alliance:export")
    @Log(title = "加盟信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Alliance alliance)
    {
        List<Alliance> list = allianceService.selectAllianceList(alliance);
        ExcelUtil<Alliance> util = new ExcelUtil<Alliance>(Alliance.class);
        return util.exportExcel(list, "加盟信息数据");
    }

    /**
     * 新增加盟信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存加盟信息
     */
    @RequiresPermissions("sso:alliance:add")
    @Log(title = "加盟信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Alliance alliance)
    {
        return toAjax(allianceService.insertAndUpdateAlliance(alliance));
    }

    /**
     * 修改加盟信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Alliance alliance = allianceService.selectAllianceById(id);
        mmap.put("alliance", alliance);
        return prefix + "/edit";
    }

    /**
     * 修改保存加盟信息
     */
    @RequiresPermissions("sso:alliance:edit")
    @Log(title = "加盟信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Alliance alliance)
    {
        return toAjax(allianceService.updateAlliance(alliance));
    }


}
